package com.liuzu.esys.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liuzu.esys.common.LayuiPageVo;
import com.liuzu.esys.mapper.GradeMapper;
import com.liuzu.esys.pojo.Grade;
import com.liuzu.esys.service.GradeService;
import com.liuzu.esys.vo.ColumnarPieVo;
import com.liuzu.esys.vo.ColumnarVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("gradeService")
public class GradeServiceImpl implements GradeService {
    @Autowired
    private GradeMapper gradeMapper;

    @Override
    public LayuiPageVo<Grade> gradePageData(Map<String, Object> params) {
        //mybatis 的分页插件
        Integer page = Integer.parseInt(params.get("page") + "");

        Integer limit = Integer.parseInt(params.get("limit") + "");

        PageHelper.startPage(page, limit);

        List<Grade> grades = gradeMapper.selectByParams(params);

        //mybatis 的分页数据结构
        PageInfo<Grade> gradePageInfo = new PageInfo<>(grades);

        //把mybatis 的分页数据封装到 layui 的分页数据结构中
        LayuiPageVo<Grade> GradesLayuiPageVo = new LayuiPageVo<>();
        GradesLayuiPageVo .setCode(0); //layui 默认0 是正确状态
        GradesLayuiPageVo .setMsg("分页列表数据");  //提示信息
        GradesLayuiPageVo .setCount(gradePageInfo.getTotal());//总记录数
        GradesLayuiPageVo .setData(gradePageInfo.getList());

        return GradesLayuiPageVo;

    }

    @Override
    public int addGrade(Grade grade) {
        int i = gradeMapper.insertSelective(grade);
        return i;
    }

    @Override
    public int deleteGrade(Integer phone) {
        return gradeMapper.deleteKey(phone) ;
    }

    @Override
    public int updateGrade(Grade grade) {
        int i = gradeMapper.updateGrade(grade);
        return i;
    }

    @Override
    public List<ColumnarVo> ageBarData() {
        List<ColumnarVo> list = gradeMapper.ageBarData();
        return list;
    }

    @Override
    public List<ColumnarPieVo> agePieData() {
        List<ColumnarPieVo> list = gradeMapper.agePieData();
          return list;
    }


}
